//
//  HiOptISystem.m
//  blackjack
//
//  Created by Thi Nguyen Tran on 3/17/10.
//  Copyright 2010 Epsilon. All rights reserved.
//

#import "HiOptISystem.h"

#define MAX_DECKS	6

@interface HiOptISystem (Private)

int numberOfCount_;
int sumOfResult_;
int trace_[1000];
int undo_;
float result_;

- (void)changeLabel;

@end


@implementation HiOptISystem

@synthesize delegate;

- (IBAction)hiButtonTouched {
	sumOfResult_--;
	
	[leftShadow setHidden:YES];
	[rightShadow setHidden:NO];
	
	trace_[undo_] = +1;
	undo_++;
	[self changeLabel];
	
}
- (IBAction)loButtonTouched {
	sumOfResult_++;
	numberOfCount_++;
	
	[leftShadow setHidden:NO];
	[rightShadow setHidden:YES];
	
	trace_[undo_] = -1;
	undo_++;
	[self changeLabel];
}
- (IBAction)undoButtonTouched {
	if (numberOfCount_ != 0)
	{
		numberOfCount_ --;
		undo_--;
		sumOfResult_ += trace_[undo_];
	}
	[self changeLabel];
}
- (IBAction)newdeckButtonTouched {
	remainDeck_--;
	if(remainDeck_ == 0) {
		remainDeck_ = MAX_DECKS;
	}
	[self changeLabel];	
}

- (IBAction)backButtonTouched {
	[delegate backToMainMenu];
}

- (void)resetContent {
	numberOfCount_ = 0;
	sumOfResult_ = 0;
	remainDeck_ = MAX_DECKS;
	undo_ = 0;
	[self changeLabel];
}
- (void)changeLabel
{
	[countingResult setText:[NSString stringWithFormat:@"%.1f", (float)sumOfResult_/(float)remainDeck_]];
	[numberCounting setText:[NSString stringWithFormat:@"%d", sumOfResult_]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)dealloc {
    [super dealloc];
}


@end
